﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CCWin;
using System.IO;
using WMPLib;
using KsMusic.API;
using KsMusic.Model;
using KsMusic.ControlCenter;
using KsMusic.common;
using static System.Windows.Forms.ListView;
using System.Collections;

namespace KsMusic
{
    public partial class MainForm : CCSkinMain
    {
        private OpenFileDialog openFileDialog1 = new OpenFileDialog();
        private string[] MusicFileNames;
        private WindowsMediaPlayer axWindowsMediaPlayer1 = new WindowsMediaPlayer();
        private FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
        private int playStatue = 0; // 播放状态

        private List<MPlaySong> listMusics = new List<MPlaySong>(); // 搜索播放歌曲信息
        private MSongList listSongs = new MSongList();  // 歌曲列表
        private int loadType = 0;   // 1:搜索，2推荐

        public delegate void Pt();

        /// <summary>
        /// timer 委托
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        // private delegate void EnableButtonCallBack(object source, System.Timers.ElapsedEventArgs e);

        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            // 搜索文本初始化
            skinTextBox1.Text = ConfigHelper.GetAppConfig("searchCache");
        }

        /// <summary>
        /// 关闭窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinPictureBox8_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == MessageBox.Show("确认退出？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information))
            {
                Application.Exit();
            }
        }

        /// <summary>
        /// 最小化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinPictureBox7_Click(object sender, EventArgs e)
        {
            WindowState = FormWindowState.Minimized;
        }

        /// <summary>
        /// 最大化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinPictureBox12_Click(object sender, EventArgs e)
        {
            MessageBox.Show("哎呀！用最标准的大小吧，不然影响美观");

            //if (WindowState == FormWindowState.Normal)
            //{
            //    WindowState = FormWindowState.Maximized;
            //}
            //else
            //{
            //    WindowState = FormWindowState.Normal;
            //}
        }

        private void skinPictureBox7_MouseMove(object sender, MouseEventArgs e)
        {
            skinPictureBox7.BackColor = Color.DimGray;
        }

        private void skinPictureBox7_MouseLeave(object sender, EventArgs e)
        {
            skinPictureBox7.BackColor = Color.Transparent;
        }

        private void skinPictureBox12_MouseMove(object sender, MouseEventArgs e)
        {
            skinPictureBox12.BackColor = Color.DimGray;
        }

        private void skinPictureBox12_MouseLeave(object sender, EventArgs e)
        {
            skinPictureBox12.BackColor = Color.Transparent;
        }

        private void skinPictureBox8_MouseMove(object sender, MouseEventArgs e)
        {
            skinPictureBox8.BackColor = Color.DimGray;
        }

        private void skinPictureBox8_MouseLeave(object sender, EventArgs e)
        {
            skinPictureBox8.BackColor = Color.Transparent;
        }



        /// <summary>
        /// 搜索框，点击图标
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinTextBox1_IconClick(object sender, EventArgs e)
        {
            // MessageBox.Show("你点击了搜索");
            string key = skinTextBox1.Text.Trim();

            if (string.IsNullOrEmpty(key))
            {
                MessageBox.Show("请输入歌曲名或歌手");
                return;
            }

            ConfigHelper.UpdateAppConfig("searchCache", key);

            // MKuwo listMusics = KuWoMusicAPI.search(key); // BaiduMusicAPI.Search(skinTextBox1.Text, 0);
            listMusics = new MusicController().QuerySong(key);

            if (listMusics == null || listMusics.Count <= 0)
            {
                MessageBox.Show("没有搜索到歌曲");
                return;
            }

            skinPictureBox16.Visible = false;
            skinBtnPlayAll.Visible = true;
            skinBtnAddS.Visible = true;
            skinBtnDown.Visible = true;
            skinLabelSearch.Visible = true;
            skinLabelSearch.Text = "搜索到“" + key + "”的相关歌曲";


            skinListView1.Clear();
            skinListView1.GridLines = false;//显示行与行之间的分隔线  
            skinListView1.MultiSelect = false; // 同时选中多项
            skinListView1.FullRowSelect = true;//要选择就是一行    
            skinListView1.View = View.Details;//定义列表显示的方式   
            skinListView1.Scrollable = true;//需要时候显示滚动条    
            skinListView1.HeaderStyle = ColumnHeaderStyle.Nonclickable;
            skinListView1.HotTracking = false;
            skinListView1.HideSelection = false;//失去焦点时显示选择的项  
            skinListView1.HoverSelection = false;//当鼠标停留数秒时自动选择项 
            skinListView1.OwnerDraw = false;
            skinListView1.Visible = true;//lstView可见   
            skinListView1.BackColor = Color.White;
            skinListView1.CheckBoxes = true;

            // 针对数据库的字段名称，建立与之适应显示表头   
            checkAll.Visible = true;
            skinListView1.Columns.Add("          " + listMusics.Count, 80, HorizontalAlignment.Right);//第一个参数，表头名，第2个参数，表头大小，第3个参数，样式   
            skinListView1.Columns.Add("操作", 80, HorizontalAlignment.Center);
            skinListView1.Columns.Add("歌名", 150, HorizontalAlignment.Center);
            skinListView1.Columns.Add("歌手", 130, HorizontalAlignment.Center);
            skinListView1.Columns.Add("专辑", 100, HorizontalAlignment.Center);
            skinListView1.Columns.Add("文件大小", 100, HorizontalAlignment.Center);
            skinListView1.Columns.Add("收费", 100, HorizontalAlignment.Center);
            skinListView1.Columns.Add("是否首发", 99, HorizontalAlignment.Center);

            int index = 1;
            foreach (MPlaySong model in listMusics)
            {
                //载入
                // string[] SubItem = { index + "", "", model.SONGNAME, model.ARTIST, "", "", "", "" };
                ListViewItem Item = new ListViewItem(index + "");
                Item.SubItems.Add("");
                Item.SubItems.Add(model.songinfo.title);
                Item.SubItems.Add(model.songinfo.author);
                Item.SubItems.Add(model.songinfo.album_title);
                Item.SubItems.Add((model.bitrate.file_size / 1024.00 / 1024.00).ToString("#0.00") + "M");
                Item.SubItems.Add(model.bitrate.free == 1 ? "免费" : "收费");
                Item.SubItems.Add(model.songinfo.is_first_publish == 1 ? "是" : "否");

                skinListView1.Items.Add(Item);

                // 显示图片
                ListViewImageHelper mc = new ListViewImageHelper();
                skinListView1.SmallImageList = imageList4;
                //mc.ShowImage(skinListView1, index - 1, 1, imageList4, 0);
                mc.ShowImage(skinListView1, index - 1, 1, imageList4, 1);
                //mc.ShowImage(skinListView1, index - 1, 1, imageList4, 2);

                // 暂时不加入播放列表
                // IWMPMedia media = axWindowsMediaPlayer1.newMedia(model.TAG);
                // axWindowsMediaPlayer1.currentPlaylist.appendItem(media);

                index++;
            }

            skinListView1.Items[0].Selected = true;
            loadType = 1;
        }

        private void SkinListView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 推荐
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinButton1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("你点击了推荐");
            int offset = 0;

            // type=2 热歌榜
            listSongs = new MusicController().GetSongList(2, offset);

            if (listSongs == null || listSongs.song_list.Count <= 0)
            {
                MessageBox.Show("没有搜索到歌曲");
                return;
            }

            skinPictureBox16.Visible = false;
            skinBtnPlayAll.Visible = true;
            skinBtnAddS.Visible = true;
            skinBtnDown.Visible = true;
            skinLabelSearch.Visible = true;
            skinLabelSearch.Text = "搜索推荐的歌曲";


            skinListView1.Clear();
            skinListView1.GridLines = false;//显示行与行之间的分隔线  
            skinListView1.MultiSelect = false; // 同时选中多项
            skinListView1.FullRowSelect = true;//要选择就是一行    
            skinListView1.View = View.Details;//定义列表显示的方式   
            skinListView1.Scrollable = true;//需要时候显示滚动条    
            skinListView1.HeaderStyle = ColumnHeaderStyle.Nonclickable;
            skinListView1.HotTracking = false;
            skinListView1.HideSelection = false;//失去焦点时显示选择的项  
            skinListView1.HoverSelection = false;//当鼠标停留数秒时自动选择项 
            skinListView1.OwnerDraw = false;
            skinListView1.Visible = true;//lstView可见   
            skinListView1.BackColor = Color.White;
            skinListView1.CheckBoxes = true;

            // 针对数据库的字段名称，建立与之适应显示表头   
            checkAll.Visible = true;
            skinListView1.Columns.Add("          " + listSongs.song_list.Count, 80, HorizontalAlignment.Right);//第一个参数，表头名，第2个参数，表头大小，第3个参数，样式   
            skinListView1.Columns.Add("操作", 80, HorizontalAlignment.Center);
            skinListView1.Columns.Add("歌名", 150, HorizontalAlignment.Center);
            skinListView1.Columns.Add("歌手", 130, HorizontalAlignment.Center);
            skinListView1.Columns.Add("专辑", 100, HorizontalAlignment.Center);
            skinListView1.Columns.Add("语言", 100, HorizontalAlignment.Center);
            skinListView1.Columns.Add("热度", 100, HorizontalAlignment.Center);
            skinListView1.Columns.Add("排名", 99, HorizontalAlignment.Center);

            int index = 1;
            foreach (MSongListItem model in listSongs.song_list)
            {
                //载入
                // string[] SubItem = { index + "", "", model.SONGNAME, model.ARTIST, "", "", "", "" };
                ListViewItem Item = new ListViewItem(index + "");
                Item.SubItems.Add("");
                Item.SubItems.Add(model.title);
                Item.SubItems.Add(model.author);
                Item.SubItems.Add(model.album_title);
                Item.SubItems.Add(model.language);
                Item.SubItems.Add(model.hot);
                Item.SubItems.Add(model.rank);

                skinListView1.Items.Add(Item);

                // 显示图片
                ListViewImageHelper mc = new ListViewImageHelper();
                skinListView1.SmallImageList = imageList4;
                //mc.ShowImage(skinListView1, index - 1, 1, imageList4, 0);
                mc.ShowImage(skinListView1, index - 1, 1, imageList4, 1);
                //mc.ShowImage(skinListView1, index - 1, 1, imageList4, 2);

                // 暂时不加入播放列表
                // IWMPMedia media = axWindowsMediaPlayer1.newMedia(model.TAG);
                // axWindowsMediaPlayer1.currentPlaylist.appendItem(media);

                index++;
            }

            skinListView1.Items[0].Selected = true;
            loadType = 2;
        }

        /// <summary>
        /// 电台
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinButton2_Click(object sender, EventArgs e)
        {
            MessageBox.Show("你点击了电台");
        }

        /// <summary>
        /// MV
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinButton3_Click(object sender, EventArgs e)
        {
            MessageBox.Show("你点击了MV");
        }

        /// <summary>
        /// 美女秀
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinButton4_Click(object sender, EventArgs e)
        {
            MessageBox.Show("你点击了美女秀");
        }

        /// <summary>
        /// 分类
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinButton5_Click(object sender, EventArgs e)
        {
            MessageBox.Show("你点击了分类");
        }

        /// <summary>
        /// 歌手
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinButton6_Click(object sender, EventArgs e)
        {
            MessageBox.Show("你点击了歌手");
        }

        /// <summary>
        /// 排行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinButton7_Click(object sender, EventArgs e)
        {
            MessageBox.Show("你点击了排行");
        }

        /// <summary>
        /// 直播
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinButton8_Click(object sender, EventArgs e)
        {
            MessageBox.Show("你点击了直播");
        }

        /// <summary>
        /// 下载专区
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinButton9_Click(object sender, EventArgs e)
        {
            MessageBox.Show("你点击了下载专区");
        }

        /// <summary>
        /// 我的收藏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinButton10_Click(object sender, EventArgs e)
        {
            MessageBox.Show("你点击了我的收藏");
        }

        /// <summary>
        /// 我的电台
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinButton11_Click(object sender, EventArgs e)
        {
            MessageBox.Show("你点击了我的电台");
        }

        /// <summary>
        /// 下载管理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinButton12_Click(object sender, EventArgs e)
        {
            MessageBox.Show("你点击了下载管理");
        }

        /// <summary>
        /// 本地音乐
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinButton13_Click(object sender, EventArgs e)
        {
            MessageBox.Show("你点击了我的音乐");
            skinPictureBox16.Visible = false;
            skinBtnPlayAll.Visible = false;
            skinBtnAddS.Visible = false;
            skinBtnDown.Visible = false;
            skinLabelSearch.Visible = true;
            skinLabelSearch.Text = "加载到本地歌曲";


            openFileDialog1.Multiselect = true;
            openFileDialog1.InitialDirectory = "F:\\KwDownload\\song";
            openFileDialog1.Filter = "音乐文件(.mp3,.wma)|*.mp3;*.wma";
            openFileDialog1.RestoreDirectory = true;
            openFileDialog1.FilterIndex = 1;

            skinListView1.Clear();
            skinListView1.GridLines = false;//显示行与行之间的分隔线  
            skinListView1.MultiSelect = false; // 同时选中多项
            skinListView1.FullRowSelect = true;//要选择就是一行    
            skinListView1.View = View.Details;//定义列表显示的方式   
            skinListView1.Scrollable = true;//需要时候显示滚动条    
            skinListView1.HeaderStyle = ColumnHeaderStyle.Nonclickable;
            skinListView1.HotTracking = false;
            skinListView1.HideSelection = false;//失去焦点时显示选择的项  
            skinListView1.HoverSelection = false;//当鼠标停留数秒时自动选择项 
            skinListView1.OwnerDraw = false;
            skinListView1.Visible = true;//lstView可见   
            skinListView1.BackColor = Color.White;
            skinListView1.CheckBoxes = true;


            //if (null != axWindowsMediaPlayer1.currentPlaylist)
            //    axWindowsMediaPlayer1.currentPlaylist.clear();
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                MusicFileNames = openFileDialog1.FileNames;

                // 针对数据库的字段名称，建立与之适应显示表头 
                checkAll.Visible = true;
                skinListView1.Columns.Add("          " + MusicFileNames.Length, 80, HorizontalAlignment.Right);//第一个参数，表头名，第2个参数，表头大小，第3个参数，样式   
                skinListView1.Columns.Add("操作", 80, HorizontalAlignment.Center);
                skinListView1.Columns.Add("歌名", 150, HorizontalAlignment.Center);
                skinListView1.Columns.Add("歌手", 100, HorizontalAlignment.Center);
                skinListView1.Columns.Add("专辑", 100, HorizontalAlignment.Center);
                skinListView1.Columns.Add("文件大小", 100, HorizontalAlignment.Center);
                skinListView1.Columns.Add("热度", 100, HorizontalAlignment.Center);
                skinListView1.Columns.Add("音质", 99, HorizontalAlignment.Center);

                int index = 1;
                foreach (string MusicName in MusicFileNames)
                {
                    FileInfo MyFileInfo = new FileInfo(MusicName);
                    //曲名
                    string MyShortFileName = MusicName.Substring(MusicName.LastIndexOf("\\") + 1);
                    MyShortFileName = MyShortFileName.Substring(0, MyShortFileName.Length - 4);

                    // 歌手
                    string singer = MyShortFileName.Split('-')[0];
                    // 歌名
                    string songName = MyShortFileName.Split('-')[1];

                    //大小
                    float MyFileSize = (float)MyFileInfo.Length / (1024 * 1024);

                    IWMPMedia media = axWindowsMediaPlayer1.newMedia(MusicName);
                    axWindowsMediaPlayer1.currentPlaylist.appendItem(media);

                    string blbumTitle = media.getItemInfo("WM/AlbumTitle");

                    //载入
                    string[] SubItem = { index + "", "", songName, singer, blbumTitle, MyFileSize.ToString().Substring(0, 4) + "M", "", "" };
                    ListViewItem Item = new ListViewItem(SubItem);
                    skinListView1.Items.Add(Item);
                    skinListView1.Items[0].Selected = true;

                    // 显示图片
                    ListViewImageHelper mc = new ListViewImageHelper();
                    skinListView1.SmallImageList = imageList4;
                    //mc.ShowImage(skinListView1, index - 1, 1, imageList4, 0);
                    mc.ShowImage(skinListView1, index - 1, 1, imageList4, 1);
                    //mc.ShowImage(skinListView1, index - 1, 1, imageList4, 2);

                    index++;
                }
            }
        }

        /// <summary>
        /// 默认列表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinButton14_Click(object sender, EventArgs e)
        {
            MessageBox.Show("你点击了默认列表");
            skinPictureBox16.Visible = false;
            skinBtnPlayAll.Visible = false;
            skinBtnAddS.Visible = false;
            skinBtnDown.Visible = false;
            skinLabelSearch.Visible = true;
            skinLabelSearch.Text = "加载到默认列表歌曲";

            skinListView1.Clear();
            skinListView1.GridLines = false;//显示行与行之间的分隔线  
            skinListView1.MultiSelect = false; // 同时选中多项
            skinListView1.FullRowSelect = true;//要选择就是一行    
            skinListView1.View = View.Details;//定义列表显示的方式   
            skinListView1.Scrollable = true;//需要时候显示滚动条    
            skinListView1.HeaderStyle = ColumnHeaderStyle.Nonclickable;
            skinListView1.HotTracking = false;
            skinListView1.HideSelection = false;//失去焦点时显示选择的项  
            skinListView1.HoverSelection = false;//当鼠标停留数秒时自动选择项 
            skinListView1.OwnerDraw = false;
            skinListView1.Visible = true;//lstView可见   
            skinListView1.BackColor = Color.White;
            skinListView1.CheckBoxes = true;

            string path = Environment.CurrentDirectory.Substring(0, 3) + "KsMusic\\Cache";
            DirectoryInfo folder = new DirectoryInfo(path);
            FileInfo[] files = folder.GetFiles("*.mp3");
            FileInfo[] files2 = folder.GetFiles("*.wma");
            files2.CopyTo(files, 0);

            checkAll.Visible = true;
            skinListView1.Columns.Add("          " + files.Length, 80, HorizontalAlignment.Right);//第一个参数，表头名，第2个参数，表头大小，第3个参数，样式   
            skinListView1.Columns.Add("操作", 80, HorizontalAlignment.Center);
            skinListView1.Columns.Add("歌名", 150, HorizontalAlignment.Center);
            skinListView1.Columns.Add("歌手", 100, HorizontalAlignment.Center);
            skinListView1.Columns.Add("专辑", 100, HorizontalAlignment.Center);
            skinListView1.Columns.Add("文件大小", 100, HorizontalAlignment.Center);
            skinListView1.Columns.Add("热度", 100, HorizontalAlignment.Center);
            skinListView1.Columns.Add("音质", 99, HorizontalAlignment.Center);

            int index = 1;
            foreach (FileInfo file in files)
            {
                //曲名
                string MyShortFileName = file.Name;
                MyShortFileName = MyShortFileName.Substring(0, MyShortFileName.Length - 4);

                // 歌手
                string singer = MyShortFileName.Split('-')[0];
                // 歌名
                string songName = MyShortFileName.Split('-')[1];
                //大小
                float MyFileSize = (float)file.Length / 1024 / 1024;
                // 唱片

                IWMPMedia media = axWindowsMediaPlayer1.newMedia(file.FullName);
                //for (int i = 0; i < media.attributeCount; i++)
                //{
                //    string s1 = media.getAttributeName(i);
                //    string info = media.getItemInfo(s1);
                //}

                axWindowsMediaPlayer1.currentPlaylist.appendItem(media);

                string blbumTitle = media.getItemInfo("WM/AlbumTitle");

                //载入
                string[] SubItem = { index + "", "", songName, singer, blbumTitle, MyFileSize.ToString().Substring(0, 4) + "M", "", "" };
                ListViewItem Item = new ListViewItem(SubItem);
                skinListView1.Items.Add(Item);
                skinListView1.Items[0].Selected = true;

                // 显示图片
                ListViewImageHelper mc = new ListViewImageHelper();
                skinListView1.SmallImageList = imageList4;
                //mc.ShowImage(skinListView1, index - 1, 1, imageList4, 0);
                mc.ShowImage(skinListView1, index - 1, 1, imageList4, 1);
                //mc.ShowImage(skinListView1, index - 1, 1, imageList4, 2);

                index++;
            }
        }

        /// <summary>
        /// 我的列表添加
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinPictureBox4_Click(object sender, EventArgs e)
        {
            MessageBox.Show("你点击了添加列表");
            skinPictureBox16.Visible = false;
            skinBtnPlayAll.Visible = false;
            skinBtnAddS.Visible = false;
            skinBtnDown.Visible = false;
            skinLabelSearch.Visible = true;
            skinLabelSearch.Text = "加载到本地歌曲";

            skinListView1.Clear();
            skinListView1.GridLines = false;//显示行与行之间的分隔线  
            skinListView1.MultiSelect = false; // 同时选中多项
            skinListView1.FullRowSelect = true;//要选择就是一行    
            skinListView1.View = View.Details;//定义列表显示的方式   
            skinListView1.Scrollable = true;//需要时候显示滚动条    
            skinListView1.HeaderStyle = ColumnHeaderStyle.Nonclickable;
            skinListView1.HotTracking = false;
            skinListView1.HideSelection = false;//失去焦点时显示选择的项  
            skinListView1.HoverSelection = false;//当鼠标停留数秒时自动选择项 
            skinListView1.OwnerDraw = false;
            skinListView1.Visible = true;//lstView可见   
            skinListView1.BackColor = Color.White;
            skinListView1.CheckBoxes = true;
            //if (null != axWindowsMediaPlayer1.currentPlaylist)
            //axWindowsMediaPlayer1.currentPlaylist.clear();
            if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                DirectoryInfo dir = new DirectoryInfo(folderBrowserDialog1.SelectedPath);
                checkAll.Visible = true;
                skinListView1.Columns.Add("          " + dir.GetFiles("*.*").Length, 80, HorizontalAlignment.Right);//第一个参数，表头名，第2个参数，表头大小，第3个参数，样式   
                skinListView1.Columns.Add("操作", 80, HorizontalAlignment.Center);
                skinListView1.Columns.Add("歌名", 150, HorizontalAlignment.Center);
                skinListView1.Columns.Add("歌手", 100, HorizontalAlignment.Center);
                skinListView1.Columns.Add("专辑", 100, HorizontalAlignment.Center);
                skinListView1.Columns.Add("文件大小", 100, HorizontalAlignment.Center);
                skinListView1.Columns.Add("热度", 100, HorizontalAlignment.Center);
                skinListView1.Columns.Add("音质", 99, HorizontalAlignment.Center);

                int index = 1;
                foreach (FileInfo f in dir.GetFiles("*.*"))
                {
                    //曲名
                    string MyShortFileName = f.Name;
                    MyShortFileName = MyShortFileName.Substring(0, MyShortFileName.Length - 4);

                    // 歌手
                    string singer = MyShortFileName.Split('-')[0];
                    // 歌名
                    string songName = MyShortFileName.Split('-')[1];

                    //大小
                    float MyFileSize = (float)f.Length / (1024 * 1024);

                    IWMPMedia media = axWindowsMediaPlayer1.newMedia(f.FullName);
                    axWindowsMediaPlayer1.currentPlaylist.appendItem(media);
                    string blbumTitle = media.getItemInfo("WM/AlbumTitle");

                    //载入
                    string[] SubItem = { index + "", "", songName, singer, blbumTitle, MyFileSize.ToString().Substring(0, 4) + "M", "", "" };

                    ListViewItem Item = new ListViewItem(SubItem);
                    skinListView1.Items.Add(Item);
                    skinListView1.Items[0].Selected = true;

                    // 显示图片
                    ListViewImageHelper mc = new ListViewImageHelper();
                    skinListView1.SmallImageList = imageList4;
                    //mc.ShowImage(skinListView1, index - 1, 1, imageList4, 0);
                    mc.ShowImage(skinListView1, index - 1, 1, imageList4, 1);
                    //mc.ShowImage(skinListView1, index - 1, 1, imageList4, 2);

                    index++;
                }
            }
        }

        /// <summary>
        /// 播放
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinButton15_Click(object sender, EventArgs e)
        {
            if (axWindowsMediaPlayer1 == null || axWindowsMediaPlayer1.currentPlaylist == null || axWindowsMediaPlayer1.currentPlaylist.count <= 0)
            {
                MessageBox.Show("请添加音乐列表");
                return;
            }

            if (playStatue == 0)
            {
                playStatue = 1;
                skinButton15.ImageIndex = 14;
                //int i = 0;
                //ListView.CheckedListViewItemCollection items = skinListView1.CheckedItems;
                axWindowsMediaPlayer1.controls.play();
                //skinTrackBar1.Maximum = Convert.ToInt32(axWindowsMediaPlayer1.currentMedia.duration);
            }
            else
            {
                playStatue = 0;
                skinButton15.ImageIndex = 13;
                axWindowsMediaPlayer1.controls.pause();
            }

            progressTimer();
        }


        /// <summary>
        /// 下一首
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinButton17_Click(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.controls.next();
        }

        /// <summary>
        /// 上一首
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinButton16_Click(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.controls.previous();
        }

        /// <summary>
        /// 更改进度
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinTrackBar1_Scroll(object sender, EventArgs e)
        {
            if (axWindowsMediaPlayer1 == null || axWindowsMediaPlayer1.currentPlaylist == null || axWindowsMediaPlayer1.currentPlaylist.count <= 0)
            {
                MessageBox.Show("请添加音乐列表");
                return;
            }

            axWindowsMediaPlayer1.controls.currentPosition = skinTrackBar1.Value;
            progressTimer();
        }

        /// <summary>
        /// 进度Timer
        /// </summary>
        private void progressTimer()
        {
            // Timer
            System.Timers.Timer t = new System.Timers.Timer(1000); //实例化Timer类，设置间隔时间为1000毫秒；  
            t.Elapsed += new System.Timers.ElapsedEventHandler(currentProgress); //到达时间的时候执行事件； 
            t.AutoReset = true; //设置是执行一次（false）还是一直执行(true)；
            t.Enabled = true; //是否执行System.Timers.Timer.Elapsed事件；
        }

        /// <summary>
        /// 播放进度
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        private void currentProgress(object source, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                ISynchronizeInvoke synchronizer = this;
                if (synchronizer.InvokeRequired)
                {
                    MethodInvoker minvoker = new MethodInvoker(process);
                    synchronizer.Invoke(minvoker, null);
                }
                else
                {
                    process();
                }
            }
            catch (OverflowException ex1)
            {

            }
            catch (Exception ex2)
            {

            }

        }

        /// <summary>
        /// 进度
        /// </summary>
        private void process()
        {
            skinLabel8.Text = axWindowsMediaPlayer1.currentMedia.name;
            skinLabel9.Text = axWindowsMediaPlayer1.controls.currentPositionString + " /" + axWindowsMediaPlayer1.currentMedia.durationString;

            int cur = Convert.ToInt32(axWindowsMediaPlayer1.controls.currentPosition);
            //int total = Convert.ToInt32(axWindowsMediaPlayer1.currentMedia.duration);
            skinTrackBar1.Maximum = Convert.ToInt32(axWindowsMediaPlayer1.currentMedia.duration);
            skinTrackBar1.Value = cur;
        }


        private void skinButton15_MouseMove(object sender, MouseEventArgs e)
        {
            skinButton15.BackColor = Color.DimGray;
        }

        private void skinButton15_MouseLeave(object sender, EventArgs e)
        {
            skinButton15.BackColor = Color.Transparent;
        }
        private void skinButton16_MouseMove(object sender, MouseEventArgs e)
        {
            skinButton16.BackColor = Color.DimGray;
        }

        private void skinButton16_MouseLeave(object sender, EventArgs e)
        {
            skinButton16.BackColor = Color.Transparent;
        }

        private void skinButton17_MouseMove(object sender, MouseEventArgs e)
        {
            skinButton17.BackColor = Color.DimGray;
        }

        private void skinButton17_MouseLeave(object sender, EventArgs e)
        {
            skinButton17.BackColor = Color.Transparent;
        }

        private void skinButton13_MouseMove(object sender, MouseEventArgs e)
        {
            skinButton13.BackColor = Color.Black;
        }

        private void skinButton13_MouseLeave(object sender, EventArgs e)
        {
            skinButton13.BackColor = Color.Transparent;
        }

        private void skinButton12_MouseMove(object sender, MouseEventArgs e)
        {
            skinButton12.BackColor = Color.Black;
        }

        private void skinButton12_MouseLeave(object sender, EventArgs e)
        {
            skinButton12.BackColor = Color.Transparent;
        }

        private void skinButton11_MouseMove(object sender, MouseEventArgs e)
        {
            skinButton11.BackColor = Color.Black;
        }

        private void skinButton11_MouseLeave(object sender, EventArgs e)
        {
            skinButton11.BackColor = Color.Transparent;
        }

        private void skinButton10_MouseMove(object sender, MouseEventArgs e)
        {
            skinButton10.BackColor = Color.Black;
        }

        private void skinButton10_MouseLeave(object sender, EventArgs e)
        {
            skinButton10.BackColor = Color.Transparent;
        }

        private void skinButton9_MouseMove(object sender, MouseEventArgs e)
        {
            skinButton9.BackColor = Color.Black;
        }

        private void skinButton9_MouseLeave(object sender, EventArgs e)
        {
            skinButton9.BackColor = Color.Transparent;
        }

        private void skinButton8_MouseMove(object sender, MouseEventArgs e)
        {
            skinButton8.BackColor = Color.Black;
        }

        private void skinButton8_MouseLeave(object sender, EventArgs e)
        {
            skinButton8.BackColor = Color.Transparent;
        }

        private void skinButton7_MouseMove(object sender, MouseEventArgs e)
        {
            skinButton7.BackColor = Color.Black;
        }

        private void skinButton7_MouseLeave(object sender, EventArgs e)
        {
            skinButton7.BackColor = Color.Transparent;
        }

        private void skinButton6_MouseMove(object sender, MouseEventArgs e)
        {
            skinButton6.BackColor = Color.Black;
        }

        private void skinButton6_MouseLeave(object sender, EventArgs e)
        {
            skinButton6.BackColor = Color.Transparent;
        }

        private void skinButton5_MouseMove(object sender, MouseEventArgs e)
        {
            skinButton5.BackColor = Color.Black;
        }

        private void skinButton5_MouseLeave(object sender, EventArgs e)
        {
            skinButton5.BackColor = Color.Transparent;
        }

        private void skinButton4_MouseMove(object sender, MouseEventArgs e)
        {
            skinButton4.BackColor = Color.Black;
        }

        private void skinButton4_MouseLeave(object sender, EventArgs e)
        {
            skinButton4.BackColor = Color.Transparent;
        }

        private void skinButton3_MouseMove(object sender, MouseEventArgs e)
        {
            skinButton3.BackColor = Color.Black;
        }

        private void skinButton3_MouseLeave(object sender, EventArgs e)
        {
            skinButton3.BackColor = Color.Transparent;
        }

        private void skinButton2_MouseMove(object sender, MouseEventArgs e)
        {
            skinButton2.BackColor = Color.Black;
        }

        private void skinButton2_MouseLeave(object sender, EventArgs e)
        {
            skinButton2.BackColor = Color.Transparent;
        }

        private void skinButton1_MouseMove(object sender, MouseEventArgs e)
        {
            skinButton1.BackColor = Color.Black;
        }

        private void skinButton1_MouseLeave(object sender, EventArgs e)
        {
            skinButton1.BackColor = Color.Transparent;
        }

        private void skinButton14_MouseMove(object sender, MouseEventArgs e)
        {
            skinButton14.BackColor = Color.Black;
        }

        private void skinButton14_MouseLeave(object sender, EventArgs e)
        {
            skinButton14.BackColor = Color.Transparent;
        }

        /// <summary>
        /// 播放全部
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinBtnPlayAll_Click(object sender, EventArgs e)
        {
            MessageBox.Show("请先下载，从本地加载播放");
        }

        /// <summary>
        /// 添加选中项
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinBtnAddS_Click(object sender, EventArgs e)
        {
            MessageBox.Show("功能暂时未开通");
        }

        /// <summary>
        /// 下载选中项
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinBtnDown_Click(object sender, EventArgs e)
        {
            this.BeginInvoke(new Pt(download));
        }

        public void download()
        {
            if (loadType == 1 && (null == listMusics || listMusics.Count <= 0))
            {
                MessageBox.Show("没有可供下载的");
                return;
            }

            if (loadType == 2 && (null == listSongs || listSongs.song_list.Count <= 0))
            {
                MessageBox.Show("没有可供下载的");
                return;
            }

            // 开始下载
            // SelectedListViewItemCollection selected = skinListView1.SelectedItems;
            CheckedIndexCollection checkedIndexs = skinListView1.CheckedIndices;
            if (checkedIndexs.Count <= 0)
            {
                MessageBox.Show("请选中下载歌曲");
                return;
            }

            IEnumerator enumerator = checkedIndexs.GetEnumerator();
            while (enumerator.MoveNext())
            {
                int index = Convert.ToInt32(enumerator.Current.ToString());
                if (loadType == 1)
                {
                    MPlaySong item = listMusics[index];
                    string path = new MusicController().DownLoadSong(item);
                }
                else if (loadType == 2)
                {
                    MSongListItem item = listSongs.song_list[index];
                    string path = new MusicController().DownLoadSong(item);
                }
            }

            MessageBox.Show("下载成功");
        }

        /// <summary>
        /// 手动选中某项是，全选CheckBox变为未选中
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinListView1_ItemChecked(object sender, ItemCheckedEventArgs e)
        {
            this.checkAll.Checked = false;
        }

        /// <summary>
        /// 全选或者不选
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void checkAll_Click(object sender, EventArgs e)
        {
            bool ischeck = checkAll.Checked;
            foreach (ListViewItem item in skinListView1.Items)
            {
                item.Checked = !ischeck;
            }

            checkAll.Checked = !ischeck;
        }

        /// <summary>
        /// 登录按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void skinLabel1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("登录成功");
            skinLabel1.Text = "游客u_10004，在线";
        }
    }
}
